package com.shenhan.threadpool;

import java.util.concurrent.*;
import java.util.stream.IntStream;

/**
 * @author shenhan
 * @create 2020/6/11 16:08
 * @description
 */
public class Demo1 {
    public static void main(String[] args) {
        /*final ExecutorService threadPool = Executors.newSingleThreadExecutor();
        final ExecutorService threadPool = Executors.newFixedThreadPool(5);
        final ExecutorService threadPool = Executors.newCachedThreadPool();*/
        ExecutorService threadPool = new ThreadPoolExecutor(2,5,3, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(3),Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy());
        try {
            IntStream.range(1, 20).forEach(i -> threadPool.execute(() -> System.out.println(Thread.currentThread().getName() + " OK")));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            threadPool.shutdown();
        }
    }
}
